YAHOO.namespace("draftrack.apidefinition.testapi");

YAHOO.draftrack.apidefinition.testapi = function() {


	var makeRequest = function (o){
		//We get the SAP from the form action
		var sUrl =  o.form.action + '?';
		
		//we get the differennt params
		var inputs = document.getElementById('testAPIForm').getElementsByTagName('input');

		if(inputs.length > 0) {
			for(var i = 0;i<inputs.length;i++) {
					sUrl += php_urlencode(inputs[i].name) + '='+ php_urlencode(inputs[i].value) +'&';
			}	
		}

		//we get the differennt params
		var selects = document.getElementById('testAPIForm').getElementsByTagName('select');
		if(selects.length > 0) {
			for(var i = 0;i<selects.length;i++) {
					sUrl += php_urlencode(selects[i].name) + '='+ php_urlencode(selects[i].value) +'&';
			}	
		}

		document.getElementById('testAPIResponse').src = sUrl;
		return false;
		//var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, callback);
	};

	var php_urlencode = function (str) {
		str = escape(str);
		return str.replace(/[*+\/@]|%20/g,
			function (s) {
				switch (s) {
					case "*": s = "%2A"; break;
					case "+": s = "%2B"; break;
					case "/": s = "%2F"; break;
					case "@": s = "%40"; break;
					case "%20": s = "+"; break;
				}
				return s;
			}
		);
	}
	


	return { 
		testAPICall:makeRequest
	        }; 
}();	
	